{include file = "styles/header.tpl"}
<div id="content" class="box">
	<h1>{if $arrResult}Edit User{else}Create User{/if}</h1>

	<form id="form" name="form" action="" target="ifrm" method="post" onsubmit="return checkFormAddUserAdmin();">
		<fieldset>
			<legend>User Information</legend>
			<table width="100%">
				 <tr>
					<td width="15%"><strong>Country:</strong></td>
					<td>
					<select name="country">
						<option value="0">Country</option>
						{foreach from=$arrCountry item=country}
						<option value="{$country.id}"{if $arrResult.country==$country.id} selected="selected"{/if}>&nbsp;+&nbsp;{$country.name}&nbsp;</option>
						{/foreach}
					</select>
						<span class="msg error hide" id="null_intCountryId">Please choose the country.</span>
					</td>
				</tr>

				<tr>
					<td width="15%"><strong>Team:</strong></td>
					<td>
						<select name="intGroupId" id="intGroupId">
							<option value="0">Team</option>
							{foreach from=$arrTeam item=team}
							<option value="{$team.id}"{if $arrResult.group_id==$team.id} selected="selected"{/if}>
								&nbsp;+&nbsp;{$team.name}&nbsp;</option>
							{/foreach}
						</select>
						<span class="msg error hide" id="null_intGroupId">Please choose the team.</span>
					</td>
				</tr>
			{if $arrResult}
				<tr>
					<td width="15%"><strong>Email:</strong></td>
					<td>
						{$arrResult.admin_username}
						<input type="hidden" size="50" name="strUsername" id="strUsername" value="{$arrResult.admin_username}" />
					</td>
				</tr>
				<tr>
					<td><strong>Password</strong></td>
					<td>
						<input type="text" size="50" name="strPasswordNew" id="strPasswordNew" />
						<input type="hidden" size="50" name="strPassword" id="strPassword" value="{$arrResult.admin_pwd}" />
						<span class="msg info">
							Leave the blank if you do not want to change user's password.
						</span>
					</td>
				</tr>
			{else}
				<tr>
					<td width="15%"><strong>Email:</strong></td>
					<td>
						<input type="text" size="50" name="strUsername" id="strUsername" />
						<span class="msg error hide" id="exists_strUsername">Email already exists.</span>
						<span class="msg error hide" id="null_strUsername">Please input the email.</span>
					</td>
				</tr>
				<tr>
					<td><strong>Password:</strong></td>
					<td>
						<input type="text" size="50" name="strPassword" id="strPassword" />
						<span class="msg error hide" id="null_strPassword">Please input the password.</span>
					</td>
				</tr>
			{/if}
			    
				<tr>
					<td width="15%"><strong>Firstname:</strong></td>
					<td><input type="text" size="50" name="strFirstname" id="strFirstname" value="{$arrResult.admin_firstname}" /></td>
				</tr>
				<tr>
					<td width="15%"><strong>Lastname:</strong></td>
					<td><input type="text" size="50" name="strLastname" id="strLastname" value="{$arrResult.admin_lastname}" /></td>
				</tr>
				<tr>
					<td width="15%"><strong>Category:</strong></td>
					<td>
						<textarea name="strCategory" id="strCategory" rows="3" cols="70">{$arrResult.category}</textarea>
						<div><em>Seperate by <strong>(;)</strong></em></div>
					</td>
				</tr>
				<tr>
					<td><strong>Status:</strong></td>
					<td>
						<select name="intActive" id="intActive">
							<option value="1">Active</option>
							<option value="0"{if $arrResult && $arrResult.admin_isactive==0} selected="selected"{/if}>Inactive</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>
						<input type="hidden" name="intAdminId" value="{$arrResult.admin_id}" />
						<input type="submit" value="{if $arrResult}Update User{else}Create User{/if}" class="bt" />
					</td>
				</tr>
			</table>
		</fieldset>
	</form>
	<iframe name="ifrm" id="ifrm" style="display:none"></iframe>
</div>
{literal}
<script type="text/javascript">
	function checkFormAddUserAdmin()
	{
		hide_all_error();
		var iCheck	= 0;
		var eFocus	= '';
		
		var id		= 'strUsername';
		var e		= $('#'+id);
		if( !e.val() )
		{
			iCheck 	= 1;
			eFocus	= eFocus ? eFocus : e;
			show_error(id, 'null');
		}
		
		var id		= 'strPassword';
		var e		= $('#'+id);
		if( !e.val() )
		{
			iCheck 	= 1;
			eFocus	= eFocus ? eFocus : e;
			show_error(id, 'null');
		}
		
		var id		= 'intGroupId';
		var e		= $('#'+id);
		if( e.val()=='0' || e.val()==0)
		{
			iCheck 	= 1;
			eFocus	= eFocus ? eFocus : e;
			show_error(id, 'null');
		}
		
		if(iCheck==1)
		{
			eFocus.focus();
			return false;
		}
		
		showWaiting();
		return true;
	}
	
	function submit_done()
	{
		window.location.href	= HOST_ADMIN + '/user';
	}
</script>
{/literal}
{include file = "styles/footer.tpl"}